<script setup lang="ts">
import { getMyComments } from '@/api/post'
import { ref } from 'vue'

const comments = ref([])

// 获取评论列表
async function fetchComments() {
  const res = await getMyComments()
  comments.value = res.data
}

// 初始化加载
fetchComments()
</script>

<template>
  <view class="comments-container">
    <view class="list">
      <view v-for="(item, index) in comments" :key="index" class="comment-item">
        <view class="comment-header">
          <image class="avatar" :src="item.user?.avatar || '/static/avatar.jpg'" />
          <text class="username">
            {{ item.user?.nickname || '匿名用户' }}
          </text>
          <text class="time">
            {{ item.createdAt }}
          </text>
        </view>
        <view class="comment-content">
          <text>{{ item.content }}</text>
        </view>
        <view class="comment-footer">
          <text class="post-title">
            来自: {{ item.post?.title }}
          </text>
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.comments-container {
  padding: 20rpx;
  background-color: #f5f5f5;

  .comment-item {
    padding: 30rpx;
    margin-bottom: 20rpx;
    background: #fff;
    border-radius: 16rpx;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

    .comment-header {
      display: flex;
      align-items: center;
      margin-bottom: 20rpx;

      .avatar {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
        margin-right: 20rpx;
      }

      .username {
        font-size: 28rpx;
        font-weight: bold;
        color: #333;
        margin-right: 20rpx;
      }

      .time {
        font-size: 24rpx;
        color: #999;
      }
    }

    .comment-content {
      font-size: 28rpx;
      line-height: 1.6;
      color: #333;
      margin-bottom: 20rpx;
    }

    .comment-footer {
      .post-title {
        font-size: 24rpx;
        color: #666;
        padding-top: 10rpx;
        border-top: 1rpx solid #eee;
      }
    }
  }
}
</style>
